<?php

use console\db\Migration;

/**
 * 用户社交关系更新
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m300110_200001_t_user_relation_format extends Migration {

    /**
     * @inheritdoc
     */
    public $tableName = '{{%user_relation}}';

    /**
     * @inheritdoc
     */
    public function safeUp() {
        $tableName = $this->tableName;
        $condition = 'a.user_id=b.to_user_id';
        $set = 'a.type=1';
//        update `ln_user_relation` a inner join `ln_user_relation` b on a.user_id=b.to_user_id set a.type=1
        
        $sql = "update {$tableName} a inner join {$tableName} b on {$condition} set " . $set;
        $this->db->createCommand($sql)->execute();
    }

    /**
     * @inheritdoc
     */
    public function safeDown() {
        $this->update($this->tableName, ['type' => 0]);
    }

}
